package videoExercises;

import java.util.StringJoiner;
import java.util.TreeMap;
import java.util.function.BiConsumer;

public class Test10 {
    public static void main(String[] args) {
        String a ="aababcabcdacde";
        /*HashMap<Character ,Integer> list = new HashMap<>();
        for(int i = 0;i<a.length();i++){
            char c = a.charAt(i);
            if(list.containsKey(c)){
                Integer integer = list.get(c);
                integer++;
                list.put(c,integer);
            }
            else{
                list.put(c,1);
            }
        }
        System.out.println(list);*/
        System.out.println("---------------");
        TreeMap<Character,Integer> tree = new TreeMap<>();
        for(int i = 0;i<a.length();i++){
            char c = a.charAt(i);
            if(tree.containsKey(c)){
                Integer integer = tree.get(c);
                integer++;
                tree.put(c,integer);
            }
            else{
                tree.put(c,1);
            }
        }
        System.out.println(tree);
        StringBuilder sb =new StringBuilder();
        tree.forEach((key,value)->{
            sb.append(key).append("(").append(value).append(")");
        });
        tree.forEach(new BiConsumer<Character, Integer>() {
            @Override
            public void accept(Character key, Integer value) {
                System.out.println(key+"("+value+")");
            }
        });

        StringJoiner sj = new StringJoiner("","","");
        tree.forEach((key,value)->{
            sj.add(key+"("+value+")");
        });

        System.out.println(sb);
        System.out.println(sj);
    }
}
